/*
 * @Author: cooper
 * @Date: 2025-04-03 21:29:22
 * @Wechat: cmd_develop
 * @Description:
 */
#ifndef __REGKEY
#define __REGKEY
#include <common.h>
void reg_init(void);

#define WAITTIME 1000 // 超时设置

#define MOTO_ZERO 0
#define MOTO_POS 1
#define WORK_WAIT 99

#define WORK_SALE 1    // 出货肠
#define WORK_BAKE 2    // 烤制肠
#define WORK_CHECK 3   // 检测烤位有无烤肠
#define WORK_ABANDON 4 // 丢弃肠
#define WORK_MOVE 5    // 移动肠
#define WORK_ARM_CAL 6 // 机械臂回原点,校准
#define WORK_TEST 99   // 测试用

#define ARM_KEYS_NUM 30      // 已知的键数量
#define ARM_LONG_KEYS_NUM 3  // 已知的键数量
#define ARM_SHORT_KEYS_NUM 3 // 已知的键数量
#define ARM_Z_KEYS_NUM 3     // 已知的键数量
#define ARM_PAW_KEYS_NUM 5   // 已知的键数量
#define ARM_STICK_KEYS_NUM 5 // 已知的键数量

#define LIFT_UPDOWN_KEYS_NUM 8
#define LIFT_DOOR_KEYS_NUM 5

#define FOOD_ONE_KEYS_NUM 5
#define FOOD_TWO_KEYS_NUM 5
#define FOOD_THREE_KEYS_NUM 5
#define FOOD_FOUR_KEYS_NUM 5

#define SALEDOOR_SPEED 2500     // 售货门的速度
#define SALEDOOR_OPEN_SET 2500  // 售货门打开
#define SALEDOOR_CLOSE_SET 1525 // 售货门关闭

extern unsigned int ARM_REG[ARM_KEYS_NUM];
extern unsigned int LONG_ARM_REG[ARM_LONG_KEYS_NUM];
extern unsigned int SHORT_ARM_REG[ARM_SHORT_KEYS_NUM];
extern unsigned int Z_ARM_REG[ARM_Z_KEYS_NUM];
extern unsigned int PAW_ARM_REG[ARM_PAW_KEYS_NUM];
extern unsigned int STICK_ARM_REG[ARM_STICK_KEYS_NUM];

extern unsigned int UPDOWN_LIFT_REG[LIFT_UPDOWN_KEYS_NUM];
extern unsigned int DOOR_LIFT_REG[LIFT_DOOR_KEYS_NUM];

extern unsigned int ONE_FOOD_REG[FOOD_ONE_KEYS_NUM];
extern unsigned int TWO_FOOD_REG[FOOD_TWO_KEYS_NUM];
extern unsigned int THREE_FOOD_REG[FOOD_THREE_KEYS_NUM];
extern unsigned int FOUR_FOOD_REG[FOOD_FOUR_KEYS_NUM];

typedef enum
{
    REG_SPEED,
    REG_ACC,
    REG_ERROR_TIMES,
    REG_POS_0,
    REG_POS_1,
    REG_POS_2,
    REG_POS_3,
    REG_POS_4,
    REG_POS_5,
    REG_POS_6,
    REG_POS_7,
    REG_POS_8,
    REG_POS_9,
    REG_POS_10,
    REG_POS_11,
    REG_POS_12,
    REG_POS_13,
    REG_POS_14,
    REG_POS_15,
    REG_POS_16,
    REG_POS_17,
    REG_POS_18
} Reg_key;

typedef enum
{
    ARM_POS_0 = 0,  // 原点
    ARM_BAKE_POS_1, // 烤位1
    ARM_BAKE_POS_2,
    ARM_BAKE_POS_3,
    ARM_BAKE_POS_4,
    ARM_BAKE_POS_5,
    ARM_BAKE_POS_6,
    ARM_BAKE_POS_7,
    ARM_BAKE_POS_8,
    ARM_BAKE_POS_9,
    ARM_BAKE_POS_10,
    ARM_BAKE_POS_11,
    ARM_BAKE_POS_12,
    ARM_BAKE_POS_13,
    ARM_BAKE_POS_14,
    ARM_BAKE_POS_15,
    ARM_BAKE_POS_16,
    ARM_BAKE_POS_17,
    ARM_BAKE_POS_18,
    ARM_BAKE_POS_19,
    ARM_BAKE_POS_20,
    ARM_BAKE_POS_21,
    ARM_BAKE_POS_22,
    ARM_BAKE_POS_23,
    ARM_BAKE_POS_24,
    ARM_BAKE_POS_25,
    ARM_BAKE_POS_26,
    ARM_BAKE_POS_27,
    ARM_BAKE_POS_28,         // 烤位28
    ARM_READY_SALE_POS,      // 准备出货  29
    ARM_SALE_POS,            // 出货      30
    ARM_REPLENISH_FRONT_POS, // 前补货      31
    ARM_REPLENISH_BACK_POS,  // 后补货      32
    ARM_READY_STICK_POS,     // 准备穿签    33
    ARM_STICK_POS,           // 穿签        34
    ARM_ABANDON_POS,         // 丢弃        35
    ARM_READY_ABANDON_POS,   // 准备丢弃    36
    ARM_RELEASE_BAKE_POS,    // 释放烤位    37

    // 签盒 38
    LCD_STICK_POS,
    // 升降机 39
    UPDOWN_LIFT_POS,
    // 补货门 40
    UPDOWN_DOOR_POS,
    // 肠盒1-4 41-44
    UPDOWN_FOOD1_POS,
    UPDOWN_FOOD2_POS,
    UPDOWN_FOOD3_POS,
    UPDOWN_FOOD4_POS,
} ARM_POS_KEY;

typedef struct
{
    /* data */
    u32 LONG_POS;
    u32 SHORT_POS;
    u32 Z_POS;
} ARM_POS_STRUCT;

typedef struct
{
    /* data */
    u16 REG_SPEED;
    u16 REG_ACC;
    u8 REG_ERROR_TIMES;
} ARM_SPEED_STRUCT;

extern ARM_SPEED_STRUCT SPEED_LONG;
extern ARM_SPEED_STRUCT SPEED_SHORT;
extern ARM_SPEED_STRUCT SPEED_Z;
extern ARM_SPEED_STRUCT SPEED_PAW;
extern ARM_SPEED_STRUCT SPEED_STICK;
extern ARM_SPEED_STRUCT SPEED_LIFT;
extern ARM_SPEED_STRUCT SPEED_DOOR;
extern ARM_SPEED_STRUCT SPEED_FOOD1;
extern ARM_SPEED_STRUCT SPEED_FOOD2;
extern ARM_SPEED_STRUCT SPEED_FOOD3;
extern ARM_SPEED_STRUCT SPEED_FOOD4;
extern ARM_POS_STRUCT ARM_POS[UPDOWN_FOOD4_POS + 1];

// 烤位情况
typedef struct
{
    u8 priority;        /* 烤制优先级 数字越小越优先*/
    u8 long_pos;        /* 长轴定位 */
    u8 short_pos;       /* 短轴定位 */
    u8 right_pos;       /* 右烤位 */
    u8 left_pos;        /* 左烤位 */
    u8 right_pipe;      /* 右烤管 */
    u8 left_pipe;       /* 左烤管 */
    u8 state;           // 当前状态,0空闲,1烤制,2保温
    u8 taste;           // 烤制口味
    u16 cur_temputure;  // 当前温度
    u16 bake_temputure; // 烤制温度
    u16 bake_time;      // 烤制时间
    u16 keep_temputure; // 保温温度
} bakepos_config;
#define BAKEPOS_TOTAL 28 // 一共多少个烤位
extern bakepos_config BP_CONFIG[BAKEPOS_TOTAL];

#endif
